﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.ComponentModel;

namespace JQueryControlToolkit.Controls
{
    [PersistChildren(false)]
    [ParseChildren(true, "Chaining")]
    [DefaultProperty("Chaining")]
    public class Animation : JQueryAction, IAnimation
    {
        public Animation()
        {
            Chaining = new Container<JQueryAction>();
            Duration = 500;
            Easing = "linear";
        }

        protected override string jQueryFunction
        {
            get { return "animate"; }
        }

        public string Style { get; set; }

        public int Duration { get; set; }

        public string Easing { get; set; }

        [PersistenceMode(PersistenceMode.InnerDefaultProperty)]
        public Container<JQueryAction> Chaining { get; set; }

        protected override Dictionary<string, object> EvaluateParameters(Dictionary<string, object> properties)
        {
            List<object> unNamedParameters = new List<object>();
            unNamedParameters.Add(new CssOptions(Style, Page));
            unNamedParameters.Add(Duration);
            unNamedParameters.Add(DomResult.Escape(Easing));
            if (Chaining.Elements.Count > 0)
                unNamedParameters.Add(new JSFunction(Chaining.Elements.ToArray()));
            return new Dictionary<string, object>() { { "", unNamedParameters } };
        }
    }
}
